public class SOCompany {

	private AbstractEmployee[] employees;
	public AbstractEmployee[] getEmployees() {
		return employees;
	}


	public SOCompany(int employeeCount) {
		
		super();
		
		if (employeeCount < 0) employeeCount = 0;
		employees = new AbstractEmployee[employeeCount];
	}

	public void addEmployee(AbstractEmployee employee) {
		
		int freePlace = getFreePlace();
		
		if (employee != null && !containsEmployee(employee) && freePlace >= 0) {
			employees[freePlace] = employee;
		} else {
			System.out.println("Can't add employee");
		}
	}
	public void removeEmployee(AbstractEmployee employee) {
		
		if (employee != null && containsEmployee(employee)) {
			for (int i=0; i<employees.length; i++) {
				if (employees[i] == employee) {
					employees[i] = null;
					break;
				}
			}
		} else {
			System.out.println("Can't remove employee");
		}
	}
	
	public double getSumOfSalary() {
		
		double result = 0;
		for (AbstractEmployee abstractEmployee : employees) {
			if (abstractEmployee != null)
				result += abstractEmployee.getSalary();
		}
		return result;
	}

	private boolean containsEmployee(AbstractEmployee employee) {
		
		for (AbstractEmployee abstractEmployee : employees) {
			if (abstractEmployee == employee) return true;
		}
		return false;
	}
	private int getFreePlace() {
		for (int i=0; i<employees.length; i++) {
			if (employees[i] == null) return i;
		}
		return -1;
	}
}
